home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: comp.vuw.ac.nz!cscnews!not-for-mail
- From: b_brown@staff.cit.ac.nz (Brian Brown)
- Subject: Re: how to use bioscom in turbo C
- Message-ID: <2c7cc$7380.17@cscnews>
- Date: Sun, 11 Feb 1996 19:55:59 GMT
- Organization: Central Institute of Technology
- X-Newsreader: WinVN 0.99.2
- References: <4fimc0$ksj@ns2.emirates.net.ae>
- MIME-Version: 1.0
-
- In article <4fimc0$ksj@ns2.emirates.net.ae>, kannan@emirates.net.ae says...
- >
- >I am trying to send information through the RS232 (com port) to a
- >burning machine. I know bioscom command is meant for RS232 interface.
- >Can someone give me an example of setting this port first (lets say
- >9600 baud, no parity, 1 stop bit, 8 char) & send the info to this
- >after checking the port is ready.
- >
- >thanx for any help.
- >
- RS232 BIOS CALLS
-
- INT 14H This interrupt provides support for RS232 communications. The AH register value, on entry,
- determines the function to be performed.
-
- AH = 0 reset port, DX = 0 = com1
- return value in AL
- 7,6,5 Baud rate 000 = 110 100 = 1200
- 001 = 150 101 = 2400
- 010 = 300 110 = 4800
- 011 = 600 111 = 9600
- 4,3 Parity (00,10=off) (01=odd, 11=even)
- 2 Stops (0=One, 1=Two stops)
- 1,0 Word Size (10=7,11=8)
- AH = 1 xmit a character, character in AL
- AH = 2 recieve a character, returns character in AL
- AH = 3 return status
-
-
- Now, lets develop routines in C to program the rs232 card using the int 14 BIOS call, ie, the
- bioscom() function in TurboC.
-
- #include <dos.h>
- int bioscom( cmd, byte, port )
- int cmd;
- char byte;
- int port;
- {
- union REGS regs;
- regs.x.dx = port;
- regs.h.ah = cmd;
- regs.h.al = byte;
- int86( 0x14, ®s, ®s );
- return( regs.x.ax );
- }
-
-
- Now, lets develop routines to initialise the specified comport, and to transmit and recieve
- characters, without resorting to using int 14h. These types of routines
- directly program the rs232 card, thus are ideal for embedded applications, ie, ROMMABLE code.
-
- /*- Initiliase the RS232 serial card -*/
- #define INP inportb
- #define OUTP outportb
- /* Defines for RS232 communications */
- #define DLL 0 /* divisor latch low byte */
- #define DLH 1 /* divisor latch high byte */
- #define THR 0 /* transmit hold register */
- #define RBR 0 /* recieve buffer register */
- #define IER 1 /* interrupt enable register */
- #define LCR 3 /* line control register */
- #define MCR 4 /* modem control register */
- #define LSR 5 /* line status register */
- #define MSR 6 /* modem status register */
- #define RTS 0x02 /* request to send */
- #define CTS 0x10 /* clear to send */
- #define DTR 0x01 /* data terminal ready */
- #define DSR 0x20 /* data set ready */
- #define RBF 0x01 /* bit 0 of LSR, rec buf full */
- #define THRE 0x20 /* bit 5 of LSR, trans reg 0 */
- #define DISINT 0x00 /* disable interrupts in IER */
- #define ABRG 0x83 /* access baud rate generator */
- /**/
-
- void rs232_init( com_port, baud rate, parity, stops, word_size )
- int com_port, baud_rate, word_size, stops;
- char *parity;
- {
- unsigned int divisorh, divisorl, format, acia[2];
- int far *bios = 0x00400000l;
- acia[0] = *bios; /* pick up address of com1 routine */
- acia[1] = *(bios + 1); /* pick up address of com2 routine */
- OUTP(acia[com_port] + IER, DISINT ); /* disable ints */
- OUTP(acia[com_port] + LCR, ABRG ); /* access baud rate gen*/
- switch( baud_rate ) {
- /* rem case 75, 110, 135, 150, 200, 1800, 19200 */
- case 300 : divisorh = 01; divisorl = 0x80; break;
- case 600 : divisorh = 00; divisorl = 0xc0; break;
- case 1200 : divisorh = 00; divisorl = 0x60; break;
- case 2400 : divisorh = 00; divisorl = 0x30; break;
- case 4800 : divisorh = 00; divisorl = 0x18; break;
- case 9600 : divisorh = 00; divisorl = 0x0c; break;
- default: printf("\nrs232_init: Error: Baud rate invalid.\n");
- return -1;
- } /* end of switch */
- OUTP(acia[com_port] + DLL, divisorl );
- OUTP(acia[com_port] + DLH, divisorh );
- format = 0; /* This sets bit 6 and 7 to zero */
- if( (strcmp( parity, "E" ) == 0) || (strcmp( parity, "O" ) == 0) ) {
- format = format 0x28; /* set bit 3 and 5 */
- if( strcmp( parity, "E" ) == 0 )
- format = format 0x10; /* set bit 4 */
- }
- if( stops == 2 )
- format = format 0x04;
- switch( word_size ) {
- case 8 : format = format 0x03; break;
- case 7 : format = format 0x02; break;
- case 6 : format = format 0x01; break;
- case 5 : break;
- default: printf("\nrs232_init: Unsupported word length.\n");
- return -1;
- } /* end of switch */
- OUTP(acia[com_port] + LCR, format );
- return 0;
- }
-
- /* Transmit a single character to RS232 card -*/
- void transmit( byte )
- char byte;
- {
- OUTP(acia[comport] + MCR, (RTS | DTR) ); /* assert RTS and DTR */
- while((INP(acia[comport] + LSR) & THRE)==0) /* trans reg empty? */
- ;
- OUTP(acia[comport] + THR, byte ); /* write character to THR */
- OUTP(acia[comport] + MCR, 0 );
- }
-
- /* Receive a single character from RS232 card */
- char receive() {
- char byte;
- OUTP(acia[comport] + MSR, (RTS | DTR) );
- while((INP(acia[comport]+LSR)&RBF)==0) /* has Data arrived? */
- ;
- OUTP(acia[comport] + MCR,0); /* stop all data */
- byte = INP(acia[comport] + RBR); /* get byte RBR */
- return( byte );
- }
-
-
-
-
- --
- Brian Brown
- Senior Lecturer, Computing
- Central Institute of Technology
- Trentham, Upper-Hutt
- New Zealand.
-
-
-